﻿// JScript 文件
var domain = "vancl.com";
try {
    if( document.domain.indexOf(domain)  != -1 ) {
        document.domain = domain;                 
    }
} catch (ex) {}

//打开用户上传对话框
function ShouUpfileDiag(productCode,url)
{
    var strIframe="";
    var paddwidth="20px";
    var leftMove = 0;
    var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent);
      
    if(IsIE()){ //如果是IE 执行
        paddwidth="10px";}
    if(ie6)
    {
         var scWidth = document.documentElement.clientWidth;
         leftMove = (scWidth-980)/2;
    } 
    strIframe="<table border=\"0\" cellspacing=\"0\" style=\"width:600px\"><tr><td colspan=\"2\" height=\"10px\">&nbsp;</td></tr><tr>";
    strIframe+="<td  class=\"mySty1\" align=left  style=\"padding-left:10px\"><div style=\"height:29px\" ><span> ";
    strIframe+="<img src=\"http://images.vancl.com/NewVancl/myvancl/myVancl__r2_c2.jpg\" width=\"278\" alt=\"\" height=\"29\" />";
    strIframe+="</span></div></td><td align=\"left\" style=\"padding-right:"+paddwidth+"\" class=\"mySty1\"><div style=\"height:29px; line-height:29px;text-align:right;\"><a href=\"javascript:CloseUpfileDiag();\" title=\"关闭\">×</a></div></td></tr></table>";
    strIframe+="<iframe id=\"ifrUpfile\" src=\""+url+"/user/w_userupfile.aspx?productcode="+productCode+"\" width=\"590\" height=\"300\" frameborder=\"0\" scrolling=\"no\"></iframe>";
    
      $('#addUpfileDiag').html(strIframe);
      
    $.blockUI({ 
            message: $('#addUpfileDiag'), css: { 
                top:  ($(window).height() - 300) /2 + 'px', 
                left: ($(window).width() - 600) /2 -leftMove + 'px',
                width: '590px',height: '350px' 
            }
      }); 
}

//显示MyVancl图片
function ShowMyVanclImg(url)
{
    $("#divShowImg").remove();

    var SHeight=$(window).height()-100;
    
    var SWidth=900;
    url=url.replace("small/","");

    var str=GetDivStr(SWidth,SHeight,url);
    $("body").append(str);

    $("#MyVanclImg").attr("src",url);
    
    DrawImage(document.getElementById("MyVanclImg"),(SWidth-20),(SHeight-150));
     if(IsIE()){ //如果是IE 执行
        ImgOnLoadReady("MyVanclImg",SWidth,(SHeight-150));
    } 
    //$("#MyVanclImg").LoadImage(true,SWidth,(SHeight-150),"ComShow("+SWidth+","+(SHeight-150)+")");
    SetDiag(200,200);
}



//对话框中div的字符串
function GetDivStr(SWidth,SHeight,url)
{
    var str="<div id=\"divShowImg\" style=\"display:none;padding:10px 8px 10px 12px;text-align:center\"><div id=\"divImgContent\" style=\"display:none\">";
    str+="<div id=\"divOut\" style=\"width:"+(SWidth-20)+"px;height:"+(SHeight-100)+"px;\" class=\"out\">";
    str+="<div id=\"divIn\" class=\"in\" style=\"height:"+(SHeight-100)+"px;\">";
    str+="<img src=\""+url+"\" id=\"MyVanclImg\" onload=\"DrawImage(document.getElementById('MyVanclImg'),"+(SWidth-20)+","+(SHeight-150)+",true);\" onerror=\"ImgError();\" width=200 height=200 />";
    str+="</div></div><div align=\"right\" style=\"line-height:50px; vertical-align:middle\">";
    str+="<a href=\"javascript:CloseUpfileDiag()\"><img src=\"http://images.vancl.com/NewVancl/MyVancl/close.gif\" style=\"position:relative;top:1%;\" /></a></div></div></div>";
    return str;
}

function ImgError()
{
    setTimeout("SetWH(200,200)",200);
}
function CloseUpfileDiag(){ 
     $.unblockUI(); 
     if(IsIE()){
     $(".blockUI").fadeOut("slow");}
}
//设置对话框
function SetDiag(w,h)
{
        $.blockUI({ 
            message: $('#divShowImg'), css: { 
                top:  120 + 'px', 
                left: (($(window).width() - w) /2)>0?(($(window).width() - w) /2):0 + 'px',
                width: w+'px',height:( h-50)+'px' 
            }
            
      }); 
}
//等比缩放图片
function DrawImage(ImgD,FitWidth,FitHeight,IsDiag) 
{ 
    var w=FitWidth;
    var h=FitHeight;
    var image=new Image(); 
    image.src=ImgD.src; 

    if(image.width>0 && image.height>0) 
    { 
        if(image.width/image.height>= FitWidth/FitHeight) 
        { 
            if(image.width>FitWidth) 
            { 
                w=FitWidth;
                h=(image.height*FitWidth)/image.width;
                ImgD.width=FitWidth; 
                ImgD.height=(image.height*FitWidth)/image.width; 
            } 
            else 
            { 
                w=image.width;
                h=image.height;
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            } 
        } 
        else 
        { 
            if(image.height>FitHeight) 
            { 
                h=FitHeight;
                w=(image.width*FitHeight)/image.height;
                ImgD.height=FitHeight; 
                ImgD.width=(image.width*FitHeight)/image.height; 
            } 
            else 
            { 
                w=image.width;
                h=image.height;
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            } 
        } 
    } 

    if(IsDiag==true)
    {
        setTimeout("SetWH("+w+","+h+")",200);
        w=w+20;
        h=h+100;
        setTimeout("SetDiag("+w+","+h+")",200);
        setTimeout("$(\"#divImgContent\").animate({ height: 'show', opacity: 'show' }, 'slow');",200);

    }

} 
function ComShow(w,h)
{
        setTimeout("SetWH("+w+","+h+")",0);
        w=w+20;
        h=h+100;
        setTimeout("SetDiag("+w+","+h+")",200);
        setTimeout("$(\"#divImgContent\").animate({ height: 'show', opacity: 'show' }, 'slow');",200);
}
//设置div及图片的宽度和高度
function SetWH(w,h)
{
        $("#MyVanclImg").css("height",String(h)+"px");
        $("#MyVanclImg").css("width",String(w)+"px");

        $("#divOut").css("width",String(w)+"px");
        $("#divIn").css("width",String(w)+"px");
        $("#divShowImg").css("width",String(w)+"px");

        $("#MyVanclImg").css("height",String(h)+"px");
        $("#divOut").css("height",String(h)+"px");
        $("#divIn").css("height",String(h)+"px");
        $("#divShowImg").css("height",String(h)+"px");
}

//判断图片是否加载完成
function ImgOnLoadReady(strImgD,FitWidth,FitHeight)
{
    var ImgD=document.getElementById(strImgD);
    
    if (ImgD.readyState=="complete") {
        DrawImage(ImgD,FitWidth,FitHeight);
    }
    else{
        setTimeout("ImgOnLoadReady('"+strImgD+"',"+FitWidth+","+FitHeight+");",200);
    }
}
 
//产品页 IE下进行缩放图片
function ImgReady()
{
    if(document.readyState=="complete") {
        if(document.getElementById("tdImg"))
        {
            var imgObjs=document.getElementById("tdImg").getElementsByTagName("img"); 
            if(imgObjs.length>0){
                for(var i=0;i<imgObjs.length;i++){
                    DrawImage(imgObjs[i],160,120);
                }
            }
        }

    }else{
        setTimeout("ImgReady()",500);
    }
    
}
function IsIE(){
    if(isFirefox=navigator.userAgent.indexOf("MSIE")>0)
        return true;
}

$(document).ready(function()
{
   $(".borderSty img").each(function()
   {
        $(this).LoadImage(true,160,120," ");

   })
   
   $(".pmy img").each(function()
   {
        $(this).LoadImage(true,140,100);

   })
}
)
                    